package com.walkline.app;

import java.util.Vector;

import net.rim.device.api.io.transport.TransportInfo;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
import net.rim.device.api.util.Persistable;

public class NotesAppConfig implements Persistable
{
	public static final String APP_TITLE = "Notes for BlackBerry";
	public static final String UNDERLINE = "\u0332";
	public static final String BBW_APPID = "52290899";
	//SKU: 5f79f297075c955f (blackberry_dianpingtuan_written_by_Walkline_Wang)

	public static int[] preferredTransportTypes = {TransportInfo.TRANSPORT_TCP_WIFI, TransportInfo.TRANSPORT_TCP_CELLULAR, TransportInfo.TRANSPORT_WAP2};
	public static int[] disallowedTransportTypes = {TransportInfo.TRANSPORT_BIS_B, TransportInfo.TRANSPORT_MDS, TransportInfo.TRANSPORT_WAP};

	public static final Background bgColor_Gradient=BackgroundFactory.createLinearGradientBackground(Color.GRAY, Color.GRAY, Color.BLACK, Color.BLACK);
	public static final Background bgColor_GradientBlue=BackgroundFactory.createLinearGradientBackground(0x4992ce, 0x4992ce, 0x05549d, 0x05549d);
	public static final Border border_Transparent=BorderFactory.createRoundedBorder(new XYEdges(16,16,16,16), Color.BLACK, 0, Border.STYLE_FILLED);
	public static final Background bg_Transparent=BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 0);
	public static final Border border_popup_Transparent=BorderFactory.createRoundedBorder(new XYEdges(16,16,16,16), Color.BLACK, 200, Border.STYLE_FILLED);
	public static final Background bg_popup_Transparent=BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 200);

	public static final Font FONT_LIST_TITLE = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt)+1, Ui.UNITS_pt);
	//public static final Font FONT_LIST_DESCRIPTION = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt)-1, Ui.UNITS_pt);
	public static final Font FONT_LIST_CURRENTPRICE = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt)+3, Ui.UNITS_pt);
	public static final Font FONT_LIST_LISTPRICE = Font.getDefault().derive(Font.STRIKE_THROUGH, Font.getDefault().getHeight(Ui.UNITS_pt)-2, Ui.UNITS_pt);
	public static final Font FONT_LIST_PURCHASECOUNT = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt), Ui.UNITS_pt);

	public static final Font FONT_SETTINGS_TITLE = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt)-1, Ui.UNITS_pt);
	public static final Font FONT_SETTINGS_DESCRIPTION = Font.getDefault().derive(Font.ITALIC, Font.getDefault().getHeight(Ui.UNITS_pt)-1, Ui.UNITS_pt);

	public static final Font FONT_ABOUT_TITLE = Font.getDefault().derive(Font.BOLD, Font.getDefault().getHeight(Ui.UNITS_pt)+2, Ui.UNITS_pt);
	public static final Font FONT_ABOUT_HEADLINE = Font.getDefault().derive(Font.BOLD | Font.ITALIC, Font.getDefault().getHeight(Ui.UNITS_pt), Ui.UNITS_pt);
	public static final Font FONT_ABOUT_SMALL = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt)-1, Ui.UNITS_pt);
	public static final Font FONT_ABOUT_LARGE = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt)+1, Ui.UNITS_pt);

	public static final Font FONT_MAIN_TITLE = Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight(Ui.UNITS_pt)+2, Ui.UNITS_pt);

	//Elements and Keys
	private Vector _elements;
	private static final int AUTO_LOGIN = 0;
	private static final int SAFE_MODE = 1;
	private static final int OVERWRITE = 2;
	private static final int UPLOAD_METHOD = 3;
	private static final int SECTION_SIZE = 4;
	private static final int DOWNLOAD_LOCATION = 5;
	private static final int DOWNLOAD_URI = 6;
	private static final int PREVIEW_SIZE = 7;
	private static final int USERNAME = 8;
	private static final int PASSWORD = 9;
	private static final int SHORTCUT_KEY = 10;
	private static final int FILE_ACTION = 11;
	private static final int ACCESS_TOKEN = 12;
	private static final int REFRESH_TOKEN = 13;
	private static final int EXPIRES_IN = 14;

	//Default values
	private final int MAXUPLOADFILESIZE = 20 * 1024 * 1024; //20MB
	private final int FALSE = 0;
	private final int TRUE = 1;

	//Persistent objects
	private static Vector _data;
	private static PersistentObject _store;

	private boolean _autoMode = true;
	private boolean _safeMode = false;
	private boolean _overWrite = true;
	private String _username = "";
	private String _password = "";
	private String _accessToken = "";
	private String _refresh_Token = "";
	private int _shortcutKey = 0;
	private long _expiresIn = 0;

	public NotesAppConfig()
	{
		//_elements = new Vector(15);

		//for (int i=0; i<_elements.capacity(); i++)
		//{
		//	_elements.addElement(new Object()); //(""));
		//}
	}

	private boolean getElementBoolean(int id)
	{
		boolean result = false;
		Object valueObject = _elements.elementAt(id); 

		if (valueObject instanceof Boolean)
		{
			result = ((Boolean) valueObject).booleanValue();
		}

		return result;
	}

	private int getElementInt(int id) {return Integer.parseInt(_elements.elementAt(id).toString());}

	private long getElementLong(int id) {return Long.parseLong(_elements.elementAt(id).toString());}

	private String getElementString(int id) {return (String) _elements.elementAt(id);}

	private void setElement(int id, Object value) {_elements.setElementAt(value, id);}

	public void setAutoMode(boolean value)
	{
		setElement(AUTO_LOGIN, new Boolean(value));
		_autoMode = value;
	}

	public boolean isAutoMode() {return _autoMode;}

	public void setSafeMode(boolean value) 
	{
		setElement(SAFE_MODE, new Boolean(value));
		_safeMode = value;
	}

	public boolean isSafeMode() {return _safeMode;}

	public void setOverwrite(boolean value)
	{
		setElement(OVERWRITE, new Boolean(value));
		_overWrite = value;
	}

	public boolean isOverwrite() {return _overWrite;}

	public int getShortcutKey() {return _shortcutKey;}

	public void setUsername(String value)
	{
		setElement(USERNAME, new String(value));
		_username = value;
	}

	public String getUsername() {return _username;}

	public void setAccessToken(String value)
	{
		setElement(ACCESS_TOKEN, new String(value));
		_accessToken = value;
	}

	public String getAccessToken() {return _accessToken;}

	public void setRefreshToken(String value)
	{
		setElement(REFRESH_TOKEN, new String(value));
		_refresh_Token = value;
	}

	public String getRefreshToken() {return _refresh_Token;}

	public void setExpiresIn(long value)
	{
		setElement(EXPIRES_IN, new Long(value));
		_expiresIn = value;
	}

	public long getExpiresIn() {return _expiresIn;}

	public void setPassword(String value)
	{
		setElement(PASSWORD, new String(value));
		_password = value;
	}

	public String getPassword() {return _password;}

	public boolean isAccountEmpty()
	{
		boolean result = false;

		if (_username.equals("") || _username.length() < 0 || _password.equals("") || _password.length() < 0)
		{
			result = true;
		}

		return result;
	}

	/*
	public String details()
	{
		return "Auto Mode: " + isAutoMode() +
				"\nSafe Mode: " + isSafeMode() +
				"\nOverwrite: " + isOverwrite() +
				"\nUpload Method: " + getUploadMethod() +
				"\nSection Size: " + getSectionSize() +
				"\nDownload Location: " + getDownloadLocation() +
				"\nPreview Size: " + getPreviewSize() +
				"\nShortcut Key: " + getShortcutKey() +
				"\nFile Action: " + getFileAction() +
				"\nUsername: " + getUsername() +
				"\nPassword: " + getPassword() +
				"\nDownload URI: " + getDownloadURI() +
				"\nAccess Token: " + getAccessToken() +
				"\nRefresh Token: " + getRefreshToken() +
				"\nExpires In: " + getExpiresIn();
	}
	*/

	/*
	static
	{
		_store = PersistentStore.getPersistentObject(0x59e8114dd2411b80L); //blackberry_vdisk_written_by_Walkline_Wang
	}
	*/
}